cmake_minimum_required(VERSION 3.12)

# 添加库文件，暂时不添加源码
add_library(utils_obj OBJECT "")

# 设置路径变量，指向3rdparty和项目根目录
SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_LIST_DIR}/3rdparty)
SET(UTILS_LIBRGA_SOURCE_PATH ${CMAKE_CURRENT_LIST_DIR}/..)

# 手动将3rdparty和allocator子模块添加到当前模块
include(${CMAKE_CURRENT_LIST_DIR}/allocator/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/3rdparty/CMakeLists.txt)

# 设置源文件变量，指向当前目录下 utils.cpp文件
set(UTILS_SRC
    ${CMAKE_CURRENT_LIST_DIR}/utils.cpp
)

# 若设置相关变量，就当作对应语言编译，兼容老项目
if(RGA_SOURCE_CODE_TYPE STREQUAL c)
    set_source_files_properties(${UTILS_SRC} PROPERTIES LANGUAGE C COMPILE_FLAGS "-x c")
endif()

# 为utils_obj对象添加源文件，PRIVATE：只在本库中编译使用，PUBLIC：头文件可暴露给依赖该对象库的其他target使用
target_sources(utils_obj
    PRIVATE
        ${UTILS_SRC}
    PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/utils.h
)

# 设置头文件搜索路径
target_include_directories(utils_obj
    PRIVATE
        ${UTILS_LIBRGA_SOURCE_PATH}/include
    PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}
)

SET(RGA_SAMPLES_UTILS_COMPILED "true" CACHE STRING "")
